<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>闭包的使用</title>
</head>

<body>
    <button id="add">新增</button>
    <button id="del">删除</button>
    <div id="dialog"></div>
</body>
<script>
    let add = document.getElementById("add");
    let del = document.getElementById("del");

    function fn() {
        let dialog = document.getElementById("dialog");
        return function (json) {
            dialog.innerHTML = json.html;
            let btn = document.createElement("button");
            btn.innerHTML = "确定";
            dialog.appendChild(btn);
            btn.onclick = json.btn.success;
        }
    }

    let Dialog = fn();

    add.onclick = function () {
        Dialog({
            html: `用户<input id="user"/>`,
            btn: {
                success: function () {
                    var re = document.getElementById("user");
                    console.log(re);
                    console.log(re.value);
                }
            }
        });
    }


</script>

</html>